import 'package:flutter/material.dart';

//手势的使用
main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      theme: ThemeData(primaryColor: Colors.teal, cardColor: Colors.orange),
      debugShowCheckedModeBanner: false,
      home: HYHomePage(),
    );
  }
}

class HYHomePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Flutter Demo'),
      ),
      body: Center(
        child: Stack(
          alignment: Alignment.center,
          children: [
            GestureDetector(
              onTapDown: (details) {
                print('outer click');
              },
              child: Container(
                width: 200,
                height: 200,
                color: Colors.teal,
                alignment: Alignment.center,
              ),
            ),
            IgnorePointer(
              child: GestureDetector(
                // behavior: HitTestBehavior.opaque, //不能解决冒泡
                child: Container(
                  width: 100,
                  height: 100,
                  color: Colors.orange,
                ),
                onTapDown: (details) {
                  print('inner click');
                },
              ),
            ),
          ],
        ),
      ),
      backgroundColor: Colors.white,
      floatingActionButton: FloatingActionButton(
          child: Icon(Icons.add),
          backgroundColor: Colors.teal,
          onPressed: () {
            print('FloatingActionButton click');
          }),
      floatingActionButtonLocation: FloatingActionButtonLocation.endFloat,
    );
  }
}

class GestureDetectorDemo extends StatelessWidget {
  const GestureDetectorDemo({
    Key key,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      child: Container(
        width: 200,
        height: 200,
        color: Colors.teal,
      ),
      onTapDown: (details) {
        print('手势按下');
        print(details.globalPosition);
        print(details.localPosition);
      },
      onTapUp: (details) {
        print('手势抬起');
      },
      onTapCancel: () {
        print('手势取消');
      },
      onTap: () {
        print('手势点击');
      },
      onDoubleTap: () {
        print('双击');
      },
      onLongPress: () {
        print('长按手势');
      },
    );
  }
}

class ListenerDemo extends StatelessWidget {
  const ListenerDemo({
    Key key,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Listener(
      child: Container(
        width: 200,
        height: 200,
        color: Colors.teal,
      ),
      onPointerDown: (event) {
        print('指针按下:$event');
        print(event.position);
        print(event.localPosition);
      },
      // onPointerMove: (event) {
      //   print('指针移动:$event');
      // },
      // onPointerUp: (event) {
      //   print('指针抬起:$event');
      // },
      // onPointerSignal: (event) {
      //   print('指针onPointerSignal:$event');
      // },
    );
  }
}
